package com.goodluck.goodluckim.ui.msg.viewholder;

import android.text.method.LinkMovementMethod;
import android.text.style.ImageSpan;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseViewHolder;
import com.goodluck.goodluckim.R;
import com.goodluck.goodluckim.db.model.IMMessage;
import com.goodluck.goodluckim.widget.emoji.MoonUtil;

/**
 * Created by wyj on 2018/9/10.
 */
public class MsgViewHolderText extends MsgViewHolderBase {

    private TextView mContentTv;

    @Override
    protected int getContentLayoutId() {
        return R.layout.listitem_text_message;
    }

    @Override
    protected void bindContentView(final BaseViewHolder helper, final IMMessage data, final int position) {
        mContentTv = helper.getView(R.id.content_tv);
        MoonUtil.identifyFaceExpression(mContext, mContentTv, data.getMessageContent(), ImageSpan.ALIGN_BOTTOM);
        mContentTv.setMovementMethod(LinkMovementMethod.getInstance());

        mContentTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MsgViewHolderText.this.onClick(helper, data, position);
            }
        });
        mContentTv.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                return MsgViewHolderText.this.onLongClick(helper, data, position);
            }
        });
    }

    @Override
    public void onClick(BaseViewHolder helper, IMMessage data, int position) {
        super.onClick(helper, data, position);
        Toast.makeText(mContext, "点击了消息:" + data.getMessageContent(), Toast.LENGTH_SHORT).show();
    }
}
